package com.tju.shortlink.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.tju.shortlink.project.common.convention.result.Result;
import com.tju.shortlink.project.common.convention.result.Results;
import com.tju.shortlink.project.dto.req.*;
import com.tju.shortlink.project.dto.resp.ShortLinkPageRespDTO;
import com.tju.shortlink.project.service.IRecycleBinService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 回收站控制层
 */
@Tag(name = "回收站控制层", description = "回收站相关功能")
@RestController
@RequestMapping("/api/short-link/v1/recycle-bin")
@RequiredArgsConstructor
public class RecycleBinController {

    private final IRecycleBinService recycleBinService;

    @Operation(summary = "将短链接移入回收站")
    @PostMapping("save")
    public Result<Void> saveRecycleBin(@RequestBody RecycleBinSaveDTO requestParam){
        recycleBinService.saveRecycleBin(requestParam);
        return Results.success();
    }

    @Operation(summary = "分页查询短链接")
    @GetMapping("page")
    public Result<IPage<ShortLinkPageRespDTO>> pageShortLink(ShortLinkRecycleBinPageReqDTO requestParam){
        return Results.success(recycleBinService.pageShortLink(requestParam));
    }

    @Operation(summary = "恢复短链接")
    @PostMapping("recover")
    public Result<Void> recoveryRecycleBin(@RequestBody RecycleBinSaveDTO requestParam){
        recycleBinService.recoveryRecycleBin(requestParam);
        return Results.success();
    }

    @Operation(summary = "删除短链接")
    @PostMapping("remove")
    public Result<Void> removeRecycleBin(@RequestBody RecycleBinRemoveDTO requestParam){
        recycleBinService.removeRecycleBin(requestParam);
        return Results.success();
    }

}
